const db = wx.cloud.database();
const app = getApp();
var tag = 0;
var arr = [];
Page({
  data: {
    question: [],
    choose: [],
    tags: 0,
    answer: '',
  },

  before: function(e) {

    tag = tag - 1;
    if (tag < 0) {
      wx.showToast({
        title: '已经是第一题！',
        icon: 'none',
        duration: 2000
      })
      tag = 0;
    } else {
      this.setData({
        tags: tag,
      })
    }
  },
  next: function(e) {
    tag = tag + 1;
    // 提交 批改后的作业
    if (tag > this.data.question.length - 1) {
      wx.showToast({
        title: '这是最后一题！',
        icon: 'none',
        duration: 2000
      })
      tag = this.data.question.length - 1
    } else {
      this.setData({
        tags: tag
      })
    }
  },
  onLoad: function(options) {
    tag = 0
    db.collection('gradeTable').get({
      success: e => {
        console.log(e)
        // 取最新的数据
        delete e.data[e.data.length-1]._id
        delete e.data[e.data.length-1]._openid
        for (let i in e.data[e.data.length-1]){
          this.data.question.push(e.data[e.data.length-1][i])
        }
        this.setData({
          question: this.data.question
        })
      },
      fail: console.error
    })
  },

})